package com.xuecheng.content.api;

import com.xuecheng.content.model.dto.BindTeachplanMediaDto;
import com.xuecheng.content.model.dto.SaveTeachplanDto;
import com.xuecheng.content.model.dto.TeachplanDto;
import com.xuecheng.content.service.TeachplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author shiminghui
 * @date 2024/8/2 17:48
 * @description: TODO
 */
@RestController
@Slf4j
@Api(tags = "课程计划相关接口")
@RequiredArgsConstructor
public class TeachplanController {

    private final TeachplanService teachplanService;

    @ApiOperation("查询课程计划树形结构")
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public List<TeachplanDto> getTreeNodes(@PathVariable Long courseId) {
        log.info("查询的课程计划id为{}", courseId);
        List<TeachplanDto> treeNodes = teachplanService.getTreeNodes(courseId);
        log.info("{}", treeNodes);
        return treeNodes;
    }

    @ApiOperation("新增或修改课程计划")
    @PostMapping("/teachplan")
    public void saveTeachplan(@RequestBody SaveTeachplanDto saveTeachplanDto) {
        log.info("保存课程计划,参数为{}", saveTeachplanDto);
        teachplanService.saveTeachplan(saveTeachplanDto);
    }

    @ApiOperation("删除课程计划分支")
    @DeleteMapping("/teachplan/{id}")
    public void deleteTeachplan(@PathVariable Long id) {
        log.info("要删除的课程计划id为{}", id);
        teachplanService.deleteTeachplan(id);
    }

    @ApiOperation("下移课程计划")
    @PostMapping("teachplan/movedown/{id}")
    public void moveDown(@PathVariable Long id) {
        log.info("下移的课程计划id{}", id);
        teachplanService.moveDowm(id);
    }

    @ApiOperation("上移课程计划")
    @PostMapping("teachplan/moveup/{id}")
    public void moveUp(@PathVariable Long id) {
        log.info("上移的课程计划id{}", id);
        teachplanService.moveUp(id);
    }

    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/teachplan/association/media")
    public void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto) {
        log.info("课程计划和媒资信息绑定,参数为:{}", bindTeachplanMediaDto);
        teachplanService.associationMedia(bindTeachplanMediaDto);
    }

    @ApiOperation(value = "课程计划和媒资信息解除绑定")
    @DeleteMapping("/teachplan/association/media/{teachPlanId}/{mediaId}")
    public void relieveAssociationMedia(@PathVariable(value = "teachPlanId") Long teachPlanId, @PathVariable(value = "mediaId") String mediaId) {
        log.info("课程计划和媒资信息解除绑定,课程id为:{},媒资文件id为:{}", teachPlanId, mediaId);
        teachplanService.relieveAssociationMedia(teachPlanId, mediaId);
    }
}
